package net.solvetheriddle.wwclient.entity;

import net.solvetheriddle.wwclient.WWLogic;
import net.solvetheriddle.wwclient.WWParser;

public class Work {

	private long id = -1;
	private long projectID;
	private String description;
	private long beginTime;
	private long endTime;

	public Work(long projectId, long beginTime) {
	    this.projectID = projectId;
	    this.description = "";
	    this.beginTime = beginTime;
	    this.endTime = 0;
	}
	
	public Work(long id, long projectId, long beginTime) {
	    this.id = id;
	    this.projectID = projectId;
	    this.description = "";
	    this.beginTime = beginTime;
	    this.endTime = 0;
	}
	
	public Work(long id, long projectID, String description, long from, long to) {
		this.id = id;
		this.projectID = projectID;
		this.description = description;
		this.beginTime = from;
		this.endTime = to;
	}
	
	/**
	 * @return ID of project this work belongs to.
	 */
	public long getProjectID() {
		return projectID;
	}

	public void setProjectID(long projectID) {
		this.projectID = projectID;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setDescription(String description) {
        this.description = description;
    }
    
    /**
     * @return ID of this work or -1 when no ID was supplied in constructor.
     */
    public long getId() {
		return id;
	}

	/**
	 * @return Text description of this work.
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return Begining time in milliseconds.
	 */
	public long getFrom() {
		return beginTime;
	}

	/**
	 * @return End time in milliseconds.
	 */
	public long getTo() {
		return endTime;
	}
	
	public void setTo(long to) {
		endTime = to;
	}
	
	/**
	 * @return Length of this work in milliseconds.
	 */
	public float getLength() {
	  	if(endTime == 0) {
	  	  return WWLogic.getCurrentMillis() - beginTime;
	  	}
		return endTime - beginTime;
	}

    @Override
    public String toString() {
        return "Work " + id + " (project: " + projectID + ", time: " + WWParser.longToTime(beginTime) + " - " + WWParser.longToTime(endTime) + ")";
    }
}
